﻿namespace _5_NovaAdmin.Infrastructure.Extensions;


/// <summary>
/// 基础响应结果（非泛型）
/// </summary>
public class ApiResult
{
    /// <summary>
    /// 状态码
    /// </summary>
    public int Code { get; set; }

    /// <summary>
    /// 消息内容
    /// </summary>
    public string Message { get; set; }

    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Status { get; set; }

    /// <summary>
    /// 创建成功响应
    /// </summary>
    public static ApiResult Ok(string message = "操作成功")
        => new ApiResult { Code = 200, Status = true, Message = message };

    /// <summary>
    /// 创建失败响应
    /// </summary>
    public static ApiResult Fail(int code = 500, string message = "操作失败")
        => new ApiResult { Code = code, Status = false, Message = message };
}

/// <summary>
/// 带数据的响应结果（泛型）
/// </summary>
public class ApiResult<T> : ApiResult
{
    /// <summary>
    /// 响应数据
    /// </summary>
    public T Data { get; set; }

    /// <summary>
    /// 创建成功响应（带数据）
    /// </summary>
    public static ApiResult<T> Ok(T data, string message = "操作成功")
        => new ApiResult<T> { Code = 200, Status = true, Message = message, Data = data };

    /// <summary>
    /// 创建失败响应（泛型版本）
    /// </summary>
    public new static ApiResult<T> Fail(int code = 500, string message = "操作失败")
        => new ApiResult<T> { Code = code, Status = false, Message = message };
}
